package com.xybbs.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.mapping.FetchType;

import com.xybbs.entity.Users;

public interface UsersMapper {
	@Insert("insert into user(userName,userNick,userPassword) values(#{userName},#{userNick},#{userPassword})")
    void insert(Users user);

	@Select("select * from user where userName=#{userName} and userPassword=#{userPassword}")
	Users selectUser(@Param("userName")String userName, @Param("userPassword")String userPassword);
	
	@Select("select * from user where userName=#{userName}")
	Users selectUserByName(@Param("userName")String userName);
	
	@Select("select * from user where userId=#{userId}")
	@Results({
		@Result(column = "userId",property = "userId"),
		@Result(column = "userId",property = "tips",
				many = @Many(select = "com.xybbs.mapper.TipsMapper.selectTipsByUserId",fetchType = FetchType.LAZY))
	})
	Users selectUserById(String userId);
	
	@Select("select * from user where userNick=#{userNick} and userId!=#{userId}")
	Users selectUserByNick(@Param("userNick")String userNick,@Param("userId")String userId);
	
	@Update("update user set userPassword = #{userPassword},userNick = #{userNick} where userId = #{userId}")
	int updateUserById(@Param("userPassword")String userPassword,@Param("userNick")String userNick,@Param("userId")String userId);
	
}